﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lazy
{
    
    class Program
    {
        static Random rc = new Random();
        static void Main(string[] args)
        {
            Console.WriteLine("输入作业序号：");
            string st = Console.ReadLine();

            switch (st)
            {
                case"1":
                    Dome01();
                    break;
                case "2":
                    Dome02();
                    break;
                case "3":
                    Dome03();
                    break;
                case "4":
                    Dome04();
                    break;
                case "5":
                    Dome05();
                    break;
                case "6":
                    Dome06();
                    break;
                case "7":
                    Dome07();
                    break;
                case "8":
                    Dome08();
                    break;
                case "9":
                    Dome09();
                    break;
                case "10":
                    Dome10();
                    break;
            }
        }
        static void Dome01() {
            Console.WriteLine("请输入一行字符串：");
            string s = Console.ReadLine();

            int letterCount = 0;
            int numConut = 0;
            int putCount = 0;
            foreach (var num in s)
            {
                if (char.IsLetter(num))
                {
                    letterCount++;
                }
                else if (char.IsNumber(num))
                {
                    numConut++;
                }
                else if (char.IsWhiteSpace(num))
                {
                    putCount++;
                }
            }
            Console.WriteLine("你输入的英文字母有{0}个，你输入的数字有{1}个，你输入的空格有{2}个。",letterCount,numConut,putCount);
            Console.ReadKey();
        }
        static void Dome02() { 
        double[] drr = new double[5];
            for (int i = 0; i < drr.Length; i++)
            {
                Console.WriteLine("请输入第"+(i+1)+"个同学的成绩：");
                drr[i] = int.Parse(Console.ReadLine());
            }
            int sum = 0;
            foreach (int num in drr)
            {
                sum += num;
            }
            int avg = sum / drr.Length;
            Console.WriteLine("成绩和为{0},平均成绩为{1}",sum,avg);
            Console.ReadKey();
        }
        static void Dome03() {
            int[] arr = new int[10];
            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = rc.Next(50);
            }

            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine(string.Join(",", arr[i]));
            }

            for (int i = 0; i < arr.Length - 1; i++)
            {
                int temp = 0;
                for (int j = 0; j < arr.Length - 1 - i; j++)
                {
                    if (arr[j] < arr[j + 1])
                    {
                        temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                }
            }

            Console.WriteLine(string.Join(",", arr));

            Console.ReadKey();
        }
        static void Dome04() {
            int[] arr = { 22, 546, 4654, 864, 546, 10, 4654, 10 };
            Console.WriteLine("请输入一个数");
            int input = int.Parse(Console.ReadLine());
            int final = -1;
            for (int i = 0; i < arr.Length; i++)
            {
                if (input - arr[i] == 0)
                {
                    final = i;
                }

            }
            if (final != -1)
            {
                Console.WriteLine(input + "最后一次出现的索引为{0}", final);
            }
            else
            {
                Console.WriteLine("{0}不存在", input);
            }
            Console.ReadKey();
        }
        static void Dome05() {
            for (int i = 1; i < 10; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write("{0} * {1} = {2}\t", i, j, i * j);
                }
                Console.WriteLine();
            }
            Console.ReadKey();
        }
        static void Dome06() {
            int a = 0;
            bool flag = true;
            while (flag)
            {
                try
                {
                    Console.WriteLine("请输入正方形边长");
                    a = Convert.ToInt32(Console.ReadLine());
                    flag = false;
                }
                catch
                {
                    Console.WriteLine("输入的不是整数，请重新输入");
                }
            }

            for (int i = 0; i < a; i++)
            {

                for (int j = 0; j < a; j++)
                {
                    if (i == 0 || i == a - 1 || j == 0 || j == a - 1)
                    {
                        Console.Write(" *");
                    }
                    else
                    {
                        Console.Write("  ");
                    }
                }
                Console.WriteLine();
            }
            Console.ReadKey();
        }
        static void Dome07() {
            Console.WriteLine("请输入你想打印的行数");

            int line = Convert.ToInt32(Console.ReadLine());

            for (int i = 1; i < line * 2; i++)
            {
                for (int j = 1; j < line * 2; j++)
                {
                    if ((j > line - i && j < line * 2 - (line - i) && i < line) || (i >= line && j > i - line && j < line * 2 - (i - line)))
                    {
                        Console.Write(" *");
                    }
                    else
                    {
                        Console.Write("  ");
                    }
                }
                Console.WriteLine("");


            }
            Console.ReadKey();
        }
        static void Dome08() {
            Console.WriteLine("请输入你想打印正方形的行数");
            int line = int.Parse(Console.ReadLine());

            for (int i = 0; i < line; i++)
            {
                for (int j = 0; j < line; j++)
                {
                    Console.Write(" *");

                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
        static void Dome09() {
            int[] arr = { 36, 369, 3469, 986, 369, 8, 3469, 8 };
            Console.WriteLine("请输入一个数");
            int input = int.Parse(Console.ReadLine());
            int final = -1;
            for (int i = 0; i < arr.Length; i++)
            {
                if (input - arr[i] == 0)
                {
                    final = i;
                }

            }
            if (final != -1)
            {
                Console.WriteLine(input + "最后一次出现的索引为{0}", final);
            }
            else
            {
                Console.WriteLine("{0}不存在", input);
            }
            Console.ReadKey();
        }
        static void Dome10() {
            Console.WriteLine("请输入杨辉三角形的长度：");
            int length = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();

            int[,] arr = new int[length, length];
            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    if (j == 0 || i == j)
                    {
                        arr[i, j] = 1;
                    }
                    else
                    {
                        arr[i, j] = arr[i - 1, j - 1] + arr[i - 1, j];
                    }
                    Console.Write(string.Join(" ", arr));
                }
                Console.WriteLine();
            }
            Console.ReadKey();
        }
    }
}
